package com.wellsoft.oa.app.activity;

import org.apache.cordova.CordovaWebView;
import org.apache.cordova.DroidGap;
import org.apache.cordova.api.CordovaInterface;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;

public class MainActivity extends DroidGap implements CordovaInterface {
	
	CordovaWebView cwv = null;
	
	protected static final String TAG = MainActivity.class.getName();
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        cwv = (CordovaWebView) findViewById(R.id.tutorialView);
        cwv.addJavascriptInterface(this, "MainActivity");
        cwv.loadUrl("file:///android_asset/www/index.html");
    }
    
    /**
     * 关闭代码
     */
    public void closeApp() {
    	new AlertDialog.Builder(this).setTitle("询问")
		   .setMessage("是否确定退出应用？")
		   .setPositiveButton("确定", new OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					MainActivity.this.finish();
				}
			  })
		   .setNegativeButton("取消", new OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
				}
		  })
		 .show();
    }
    
 
    /////////////////////////////////////////////////
	@Override
	@Deprecated
	public void cancelLoadUrl() {
	}

	@Override
	public Activity getActivity() {
		return this;
	}

	@Override
	@Deprecated
	public Context getContext() {
		return this;
	}

	@Override
    public Object onMessage(String id, Object data) {
		return null;
	}
}